/**
 * 
 */
package com.toncen.samepms.fisher.filter;

import java.util.ArrayList;
import java.util.List;

import com.toncen.samepms.fisher.formatter.CodeFormatter;
import com.toncen.samepms.system.dao.CodeDao;
import com.toncen.samepms.system.domain.Code;
import com.toncen.samepms.system.domain.CodeItem;
import com.sky.common.http.HTTPUtils;
import com.sky.fisher.condition.AbstractCondition;
import com.sky.fisher.condition.NumberEqulasCondtion;
import com.sky.fisher.condition.NumberGreaterThanCondtion;
import com.sky.fisher.condition.NumberGreaterThanEqualCondtion;
import com.sky.fisher.condition.NumberLessThanCondtion;
import com.sky.fisher.condition.NumberLessThanEqualCondtion;
import com.sky.fisher.condition.NumberNotEqulasCondtion;
import com.sky.fisher.filter.AbstractColumnFilter;
import com.sky.fisher.filter.Options;
import com.sky.fisher.model.CommonColumnModel;

/**
 * 描述：数字类型编码过滤器
 * 
 * @author tch
 * 
 */
public class CodeColumnFilter extends AbstractColumnFilter {
	private AbstractCondition[] conditons = new AbstractCondition[] { new NumberEqulasCondtion(), new NumberNotEqulasCondtion(),
			new NumberGreaterThanCondtion(), new NumberGreaterThanEqualCondtion(), new NumberLessThanCondtion(), new NumberLessThanEqualCondtion() };

	/**
	 * 
	 */
	public CodeColumnFilter() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sky.fisher.filter.AbstractColumnFilter#getConditons()
	 */
	@Override
	protected AbstractCondition[] getConditons() {
		return conditons;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sky.fisher.filter.AbstractColumnFilter#getDefaultCondition()
	 */
	@Override
	public AbstractCondition getDefaultCondition() {
		return new NumberEqulasCondtion();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sky.fisher.filter.AbstractColumnFilter#getValueOptions(com.sky.fisher.model.CommonColumnModel)
	 */
	public List<Options> getValueOptions(CommonColumnModel column) throws Exception {
		List<Options> valueOptions = new ArrayList<Options>();
		CodeDao codeDao = new CodeDao();
		String code = column.getParameterMap().get(CodeFormatter.PARAMETER_CODE);
		code = HTTPUtils.searchScopeValue(column.getGrid().getRequest(), code);// 从http范围搜索一下
		Code codeBean = codeDao.getByCode(code);
		if (codeBean == null) {
			throw new Exception("编码【" + code + "】不存在，请与系统管理员联系！");
		}
		for (CodeItem item : codeBean.getCodeItemList()) {
			valueOptions.add(new Options(item.getValue(), item.getName()));
		}
		return valueOptions;
	}

	@Override
	public String getValidateMessage() {
		return null;
	}

	@Override
	public String getValidatePattern() {
		return null;
	}
}
